﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common.Model;
using System.Data.Objects.DataClasses;
using System.Data.Objects;

namespace CBE.Model
{
    public class GenericEntityReaderDataAccess<E, DC> : AbstractEntityDataAccess<DC>, IGenericEntityReaderDataAccess<E>
        where E : EntityObject, new()
        where DC : ObjectContext, new()
    {

        #region IGenericEntityReaderDataAccess<E> Members

        private string GetEntitySet(E entity)
        {
            return entity.GetType().Name;
        }

        public virtual List<E> ReadEntities()
        {
            var list = ObjectContext.CreateQuery<E>(GetEntitySet(new E())).ToList();
            return list;
        }

        public virtual List<E> ReadEntitiesByParameter(EntityObject entityObject)
        {
            var list = ObjectContext.CreateQuery<E>(GetEntitySet(new E())).ToList();
            return list;
        }

        #endregion

    }
}